package com.lianwei.controller;

import com.lianwei.pojo.Goods;
import com.lianwei.service.GoodsService;
import com.lianwei.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品模块")
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @ApiOperation("添加商品")
    @PostMapping("/add")
    public Integer addGoods(@RequestBody Goods goods){
        Integer i = goodsService.addGood(goods);

        return i;
    }
    @ApiOperation("删除商品")
    @GetMapping("/delete/{id}")
    public Integer deleteGoods(@PathVariable Integer id){
        Integer i = goodsService.deleteGood(id);
        return i;
    }
    @ApiOperation("修改商品")
    @PostMapping("update")
    public Integer updateGoods(@RequestBody Goods goods,int id){
        Integer i = goodsService.updateGood(goods, id);
        return i;
    }
    @ApiOperation("查询商品")
    @GetMapping("/list")
    public List<Goods> queryAllGoods(){
        List<Goods> goodsList = goodsService.queryGoods();
        return goodsList;
    }

    @ApiOperation("商品id查询")
    @GetMapping("/queryid/{id}")
    public Goods queryGoodsById(@PathVariable int id){
        Goods goods= goodsService.getGoodsById(id);
        return goods;
    }

    @ApiOperation("商品名模糊查询")
    @GetMapping("/queryname")
    public List<Goods> queryGoodsLike(@RequestParam(required = true) String name){
        List<Goods> goods= goodsService.getGoodsLike(name);
        return goods;
    }
    @ApiOperation("类别查询商品")
    @GetMapping("/querycategory")
    public List<Goods> queryGoodsByCategory(@RequestParam(required = true) int categoryId){
        List<Goods> goods= goodsService.getGoodsByCategory(categoryId);
        return goods;
    }
}
